//
//  LZPaySelCounView.m
//  com.modada.new
//
//  Created by ferver7 on 2019/5/19.
//  Copyright © 2019 ferver7. All rights reserved.
//

#import "LZPaySelCounView.h"

@implementation LZPaySelCounView

-(void)awakeFromNib
{
    [super awakeFromNib];
    self.selfTableView.delegate = self;
    self.selfTableView.dataSource = self;
    self.selfTableView.tableFooterView = [UIView new];
    self.selIndex = -1;
}
-(void)setCardList:(NSArray *)cardList
{
    _cardList = cardList;
    [self.selfTableView reloadData];
}
-(void)setYunfeiArr:(NSArray *)yunfeiArr{
    _yunfeiArr = yunfeiArr;
    self.songhuofangshiLab.text = @"选择送货方式";
}
- (IBAction)sureAction:(id)sender {
    
    if (self.yunfeiArr.count) {//如果是选择运费的方式
        
        self.returnSelResule(self.yunfeiArr[self.selIndex]);
        return;
    }
    
    if (self.cardList.count == self.selIndex) {
        self.returnSelResule(@"");
    }else{
        self.returnSelResule(self.cardList[self.selIndex]);
    }
    
}
- (IBAction)closeAction:(id)sender {
    
    [GKCover hide];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.yunfeiArr.count) {
        return self.yunfeiArr.count;
    }else{
        return self.cardList.count+1;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * baseCell = [[NSBundle mainBundle]loadNibNamed:@"LZPaySelCounView" owner:nil options:nil].lastObject;
   
    UILabel * contentLabel = mViewByTag(baseCell.contentView, 100, UILabel);
    
    if (self.yunfeiArr.count) {
        contentLabel.text = self.yunfeiArr[indexPath.row];
    }else{
        if (indexPath.row < self.cardList.count) {
            NSDictionary * infoDic = self.cardList[indexPath.row];
            contentLabel.text = [NSString stringWithFormat:@"满%@减%@",infoDic[@"full"],infoDic[@"money"]];
        }else{
            contentLabel.text = @"不使用优惠券";
        }
    }
    
     return baseCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.selIndex == indexPath.row) {
        
    }else{
        self.selIndex = indexPath.row;
        UITableViewCell * baseCell = [tableView cellForRowAtIndexPath:indexPath];
        UIImageView * contentLabel = mViewByTag(baseCell.contentView, 101, UIImageView);
        contentLabel.image = mImageByName(@"xuanzhong");
    }
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * baseCell = [tableView cellForRowAtIndexPath:indexPath];
    UIImageView * contentLabel = mViewByTag(baseCell.contentView, 101, UIImageView);
    contentLabel.image = mImageByName(@"weixuanzhong");
}
@end
